package com.leizi.igym.controller.user;

import cn.hutool.core.collection.CollectionUtil;
import com.leizi.igym.dto.CategoryAddDTO;
import com.leizi.igym.dto.CategoryDTO;
import com.leizi.igym.dto.CategoryPageQueryDTO;
import com.leizi.igym.enums.ReturnCodeEnum;
import com.leizi.igym.exception.BusinessException;
import com.leizi.igym.resp.PageResult;
import com.leizi.igym.resp.Result;
import com.leizi.igym.service.CategoryService;
import com.leizi.igym.utils.ThrowUtils;
import com.leizi.igym.vo.CategoryCascaderVO;
import com.leizi.igym.vo.CategoryVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * @Author: leizi0110
 * @CreateTime: 2024-04-08  09:15
 * @Description:
 */

@RestController("userCategoryController")
@RequestMapping("/user/category")
@Tag(name = "用户端-分类相关接口")
@Slf4j
public class CategoryController {

    @Resource
    private CategoryService categoryService;


    @Operation(summary = "用户端：查询所有分类")
    @GetMapping
    public Result<List<CategoryVO>> getCategory() {
        log.info("用户端查询所有分类");
        return Result.ok(categoryService.getCategoryWithChild());
    }

    @Operation(summary = "用户端：根据id查询分类")
    @GetMapping("{id}")
    public Result<CategoryVO> getCategoryById(@PathVariable("id") Long id) {
        log.info("用户端根据id查询分类");
        CategoryVO categoryVO = categoryService.getByIdWithParent(id);
        return Result.ok(categoryVO);
    }

    @Operation(summary = "用户端：查询所有分类以级联形式返回")
    @GetMapping("cascader")
    public Result<List<CategoryCascaderVO>> getCategoryCascaderVO() {
        log.info("用户端查询所有分类以级联形式返回");
        return Result.ok(categoryService.getCategoryCascaderVO());
    }

    @Operation(summary = "用户端：获取顶级分类")
    @GetMapping("/top")
    public Result getTopCategory() {
        log.info("用户端获取顶级分类");

        List<CategoryVO> topCategory = categoryService.getTopCategory();

        return Result.ok(topCategory);
    }


}
